package com.test.rest.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.test.rest.bean.Book;
import com.test.rest.bean.Category;
import com.test.rest.dao.CategoryDao;

public class CategoryDaoImpl implements CategoryDao {

	private static Map<String, Category> categoryMap = new HashMap<String, Category>();
	private static Map<String, List<Book>> bookMap = new HashMap<String, List<Book>>();
	
	static {
		Category category1 = new Category();
		category1.setCategoryId("001");
		category1.setCategoryName("Ruby");
		
		categoryMap.put(category1.getCategoryId(), category1);
		
		Book book1 = new Book();
		book1.setAuthor("zhangsan");
		book1.setBookName("Inside Java");
		book1.setBookId("001");
		book1.setBookNumber("Number001");
		
		Book book2 = new Book();
		book2.setAuthor("lisi");
		book2.setBookName("Android Dev");
		book2.setBookId("002");
		book2.setBookNumber("Number002");
		
		List<Book> bookList = new ArrayList<Book>();
		bookList.add(book1);
		bookList.add(book2);
		
		bookMap.put(category1.getCategoryId(), bookList);
		
		
	}
	
	public Category getCategory(String id) {
		
		Category cat = null;
		
		if (null != categoryMap.get(id)) {
			
			cat = new Category();
			
			cat.setCategoryId(categoryMap.get(id).getCategoryId());
			cat.setCategoryName(categoryMap.get(id).getCategoryName());
			
		}
		
		return cat;

		
	}

	public List<Book> getBooks(String categoryId) {
		return bookMap.get(categoryId);
	}

	public void addCategory(Category category) {
		categoryMap.put(category.getCategoryId(), category);
	}

}
